package com.trxy.service.impl;

import com.trxy.mapper.PorderMapper;
import com.trxy.model.Customer;
import com.trxy.model.Detail;
import com.trxy.model.Porder;
import com.trxy.model.Product;
import com.trxy.service.PorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PorderServiceImpl implements PorderService {

    @Autowired
    PorderMapper porderMapper;

    @Override
    public Porder create(Customer customer) {
        int customerId = customer.getId();
        Date date = new Date();
        int status = 0;
        Porder porder = new Porder(customerId,date,status);
        porderMapper.create(porder);
        return porder;
    }

    @Override
    public int addDetail(Detail detail) {
        return porderMapper.addDetail(detail);
    }

    @Override
    public List<Detail> details(int porderId) {
        return porderMapper.details(porderId);
    }

    @Override
    public Porder selectByPrimaryKey(int porderId) {
        return porderMapper.selectByPrimaryKey(porderId);
    }

    @Override
    public int changeQuantity(Integer porderId, Integer productId, int target) {
        return porderMapper.changeQuantity(porderId, productId, target);
    }

    @Override
    public int commit(Integer porderId, double total, int status, String outTradeNo) {
        return porderMapper.commit(porderId, total, status, outTradeNo);
    }

    @Override
    public int changeStatus(String outTradeNo,int status) {
        return porderMapper.changeStatus(outTradeNo, status);
    }

    @Override
    public Porder selectByOutTradeNo(String outTradeNo) {
        return porderMapper.selectByOutTradeNo(outTradeNo);
    }
}
